package com.mtask.web.controller;

import com.mtask.common.dto.TaskProjectDTO;
import com.mtask.common.entity.task.TaskProject;
import com.mtask.web.service.ProjectService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/project")
@RestController
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @PostMapping
    public void save(@RequestBody TaskProject taskProject) {
        projectService.save(taskProject);
    }


    @PostMapping("/all")
    public Page<TaskProject> findAll(@RequestBody PageRequest pageable) {
        return projectService.findAll(pageable);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        projectService.deleteById(id);
    }

    @GetMapping("/simple-all")
    public List<TaskProjectDTO> simpleAll() {
        return projectService.simpleAll();
    }
}
